package com.realtyreg.webview.security;

import org.apache.log4j.Logger;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Обработчик исключений, возникших при аутентификации.
 * Просто логируют исключение, т.к. сам Spring Security этого не делает.
 * Created by Petro 09.02.13 19:19
 */
public class SimpleLoggingAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
    private static final Logger LOG = Logger.getLogger(SimpleLoggingAuthenticationFailureHandler.class);

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        LOG.error("Ошибка при аутентификации. Логин: '" + request.getParameter("j_username") + "'", exception);
        super.onAuthenticationFailure(request, response, exception);
    }
}
